package tools.chapter14;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author Kevin
 * @date 2020/2/24 13:52
 */
public class X {
    private final Lock rtl = new ReentrantLock();
    int value;

    public void addOne() {
        //获取锁
        rtl.lock();
        try {
            value += 1;
        } finally {
            //保证锁的释放
            rtl.unlock();
        }
    }
}
